#include "MediaFile.h"
#include "SDLPlayer.h"
#include<SDL\SDL.h>
void PlayFAAC(const char*name){
    MediaFile*mf=OpenMediaFile(name);
    if(mf==NULL)return;
    printf("%u %u %u %u\n",mf->AudioInfo.nChannels,mf->AudioInfo.nSamplesPerSec,mf->AudioInfo.wBitsPerSample,mf->TotalTime);
    do{
        MediaFrame*frame=GetNextMediaFrame(mf);
        InitAudioThread(frame->data,frame->datalen);
        FreeMediaFrame(frame);
    }while(0);    
    while(1){
      if(GetAudioCachePackets()<10){
         MediaFrame*frame=GetNextMediaFrame(mf);
         if(frame==NULL)break;
         PushAudioPacket(frame->data,frame->datalen);
         //printf("%u %u\n",frame->timestamp,frame->datalen);
         FreeMediaFrame(frame);
      }else{
         SDL_Delay(10);
      }
    }
    CloseMediaFile(mf);
    while(GetAudioCachePackets()>0){
      SDL_Delay(100);
    }
    ClearAudioThread();
}